package pdf.book.algorithm;

public class BinaryTest{
    public static int binary(int[] array, int value){
        int low = 0;
        int high = array.length - 1;
        while(low <= high){
            int middle = (low + high) / 2;
            if(value < array[middle]){
                high = middle - 1;
            }else if(value > array[middle]){
                low = middle + 1;
            }else{
                return middle;
            }
        }
        return -1;
    }
    public static void main(String[] args){
        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9};
        int value = binary(arr, 9);
        System.out.println(value);
//        System.out.println(a.length); # 9
    }
}

